package com.yc.cloud.openai.portal.service;

import com.fasterxml.jackson.annotation.JsonClassDescription;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import lombok.extern.slf4j.Slf4j;
 
import java.util.function.Function;
 
@Slf4j
public class WeatherService implements Function<WeatherService.Request, WeatherService.Response> {
 
    /**
     * Weather Function request.
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonClassDescription("Weather API request")
    public record Request(@JsonProperty(required = true,
            value = "location") @JsonPropertyDescription("The city and state e.g.广州") String location) {
    }
 
 
    /**
     * Weather Function response.
     */
    public record Response(String weather) {
    }
 
    @Override
    public WeatherService.Response apply(WeatherService.Request request) {
        log.info("location: {}", request.location);
        String weather = "";
        if (request.location().contains("广州")) {
            weather = "小雨转阴 13~19°C";
        } else if (request.location().contains("深圳")) {
            weather = "阴 15~26°C";
        } else {
            weather = "热到中暑 99~100°C";
        }
 
        return new WeatherService.Response(weather);
    }
}